package com.snj.wef.ranking;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.snj.lib.CustomHttpClient;
import com.snj.lib.Global;
import com.snj.lib.NewsHolder;
import com.snj.lib.RankingHolder;
import com.snj.wef.R;


public class RankingAdapter extends BaseAdapter {
	
	String tag = "RankingAdapter";
	
	Context context;
	int layout;
	
	
	ArrayList<RankingItem> mRankingList;
	
	LayoutInflater mInflater = null;
	
	
	public RankingAdapter(Context _context, int _layout, ArrayList<RankingItem> _newslist) {
		// TODO Auto-generated constructor stub
		
		this.context = _context;
		this.layout = _layout;
		this.mRankingList = _newslist;
		
	}
	
	public void Insert(ArrayList<RankingItem> mList)
	{
		mRankingList.addAll(mList);
	}
	
	public void SetList(ArrayList<RankingItem> mList)
	{
		mRankingList = mList;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return mRankingList.size();
	}

	public RankingItem getItem(int position) {
		// TODO Auto-generated method stub
		return mRankingList.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
	
		RankingHolder holder = null;
		
		if(convertView == null)
		{
			mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = mInflater.inflate(layout, parent, false);
			
			holder = new RankingHolder();
			
			holder.img_ranking = (ImageView)convertView.findViewById(R.id.img_rankingno);
			holder.txt_diff = (TextView)convertView.findViewById(R.id.txt_rankingdiff);
			holder.txt_partnername = (TextView)convertView.findViewById(R.id.txt_rankingpartername);
			holder.img_partnerimg = (ImageView)convertView.findViewById(R.id.img_rankingpartnerimg);
			
			convertView.setTag(holder);
		}
		else
		{
			holder = (RankingHolder)convertView.getTag();
		}
		
		
		
		
		holder.txt_partnername.setText(mRankingList.get(position).GetPartnerName());
		//Log.d("News", "Show Image");
		int rank = mRankingList.get(position).GetRanking();
		switch(rank)
		{
		case 0:
			holder.img_ranking.setImageResource(R.drawable.ranking_01);			
			break;
		case 1:
			holder.img_ranking.setImageResource(R.drawable.ranking_02);
			break;
		case 2:
			holder.img_ranking.setImageResource(R.drawable.ranking_03);
			break;
		case 3:
			holder.img_ranking.setImageResource(R.drawable.ranking_04);
			break;
		case 4:
			holder.img_ranking.setImageResource(R.drawable.ranking_05);
			break;
		case 5:
			holder.img_ranking.setImageResource(R.drawable.ranking_06);
			break;
		case 6:
			holder.img_ranking.setImageResource(R.drawable.ranking_07);
			break;
		case 7:
			holder.img_ranking.setImageResource(R.drawable.ranking_08);
			break;
		case 8:
			holder.img_ranking.setImageResource(R.drawable.ranking_09);
			break;
		case 9:
			holder.img_ranking.setImageResource(R.drawable.ranking_10);
			break;
		case 10:
			holder.img_ranking.setImageResource(R.drawable.ranking_11);
			break;
		case 11:
			holder.img_ranking.setImageResource(R.drawable.ranking_12);
			break;
		case 12:
			holder.img_ranking.setImageResource(R.drawable.ranking_13);
			break;
		case 13:
			holder.img_ranking.setImageResource(R.drawable.ranking_14);
			break;
		case 14:
			holder.img_ranking.setImageResource(R.drawable.ranking_15);
			break;
		case 15:
			holder.img_ranking.setImageResource(R.drawable.ranking_16);
			break;
		case 16:
			holder.img_ranking.setImageResource(R.drawable.ranking_17);
			break;
		case 17:
			holder.img_ranking.setImageResource(R.drawable.ranking_18);
			break;
		case 18:
			holder.img_ranking.setImageResource(R.drawable.ranking_19);
			break;
		case 19:
			holder.img_ranking.setImageResource(R.drawable.ranking_20);
			break;
		}
		
		holder.img_partnerimg.setImageBitmap(mRankingList.get(position).GetPartnerImage());
		
		
		
		return convertView;
	}
	
	
}
